package com.kehao.leetcode.basic.linkedList;


import java.util.Stack;

public class LinkedListSolution5 {

    class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public boolean isPalindrome(ListNode head) {
        ListNode tmp = head;
        Stack<Integer> stack = new Stack<>();
        while (tmp!=null){
            stack.push(tmp.val);
            tmp=tmp.next;
        }
        while (head!=null){
            if(head.val!=stack.pop()){
                return false;
            }
            head= head.next;
        }
        return true;
    }

}

